package com.xframe.xdal.core.param.builder;

import com.xframe.xdal.core.param.*;

import java.util.HashMap;
import java.util.Map;

public class MySqlParamFactory implements IBuilderFactory {
    private static Map<Class<?>, IParamSet> map = new HashMap<>();

    static DefParamSet defParamSet = new DefParamSet();
    static {
        map.put(java.util.Date.class,new TimestampParamSet());
        map.put(java.sql.Date.class,new SqlDateParamSet());
        map.put(java.sql.Timestamp.class,new TimestampParamSet());
        map.put(java.io.InputStream.class,new BlobParamSet());
        map.put(Enum.class,new EnumParamSet());
    }


    private static MySqlParamFactory mySqlParamFactory  = new MySqlParamFactory();

    public static MySqlParamFactory getInstance(){
        return mySqlParamFactory;
    }

    @Override
    public IParamSet getParamSet(Class<?> dataType) {
        if(java.io.InputStream.class.isAssignableFrom(dataType)){
            return map.get(java.io.InputStream.class);
        }
        if(dataType.isEnum()){
            return map.get(Enum.class);
        }
        IParamSet paramSet = map.get(dataType);

        return paramSet == null?defParamSet:paramSet;
    }
}
